home *** CD-ROM | disk | FTP | other *** search
- /*
- * WinLIB Demonstration program
- * by Ken Hollis
- */
-
- #include <winlib.h>
-
- int file_index, options_index, settings_index, c1, c2, shown;
- WINDOW *t1_win, *t2_win;
-
- void test_stop(void)
- {
- Win_Deinitialize();
- exit(0);
- }
-
- void test_win_callback(WINDOW *win, int msg)
- {
- switch(msg) {
- case WM_CREATED: wprintw(win, "Created\n"); break;
- case WM_MINIMIZED: wprintw(win, "Minimized\n"); break;
- case WM_MAXIMIZED: wprintw(win, "Maximized\n"); break;
- }
- }
-
- void test_window(void)
- {
- Win_CreateWindow(0, 1, 40, 9, "Ook-Bleah!",
- (CLOSER | MOVER | MAXIMIZER | MINIMIZER | SIZER), test_win_callback);
- }
-
- void test2_win(void)
- {
- (void) Win_CreateWindow(15, 15, 40, 9, "Ook-Bleah AGAIN",
- (CLOSER | MOVER | MAXIMIZER | MINIMIZER | SIZER), test_win_callback);
- }
-
- void c1_opt(void)
- {
- c1 = (c1 == TRUE) ? FALSE : TRUE;
- Menu_AddCheck(settings_index, "Opaquely", c1);
- }
-
- void c2_opt(void)
- {
- c2 = (c2 == TRUE) ? FALSE : TRUE;
- Menu_AddCheck(settings_index, "Color", c2);
- }
-
- void test_getlib(void)
- {
- int x = Win_GetOptions();
-
- if (!shown)
- shown++;
- else
- wprintw(_main_win, "What, once isn't enough?!\n");
-
- wprintw(_main_win, "Current library version: %s\n", Win_GetLibraryVersion());
- wprintw(_main_win, "Current library options are:\n");
- if (x & OPT_DEBUG)
- wprintw(_main_win, "\tDebugging enabled\n");
- if (x & OPT_MOUSECOORD)
- wprintw(_main_win, "\tMouse coordinates enabled\n");
- if (x & OPT_COLOR)
- wprintw(_main_win, "\tColor support enabled\n");
- if (x & OPT_SOUND)
- wprintw(_main_win, "\tSound support enabled\n");
- if (x & OPT_WAVFILE)
- wprintw(_main_win, "\tMicrosoft WAV file support enabled\n");
- if (x & OPT_USEDEVAUDIO)
- wprintw(_main_win, "\tUsing /dev/audio to play Sun Audio sounds\n");
- if (x & OPT_SOUNDINIT)
- wprintw(_main_win, "\tConnection to sound server is established\n");
- }
-
- void do_demo(void)
- {
- c1 = FALSE;
- c2 = FALSE;
- t1_win = NULL;
- t2_win = NULL;
- shown = 0;
-
- file_index = Menu_AddTitle(" File ");
- options_index = Menu_AddTitle(" Options ");
- settings_index = Menu_AddTitle(" Settings ");
-
- if (file_index) {
- Menu_AddItem(file_index, " Open a file [ALT-O] ", MENU_SELECTABLE, NULL);
- Menu_AddItem(file_index, " Close a file [ALT-C] ", MENU_SELECTABLE, NULL);
- Menu_AddItem(file_index, " Save a file [ALT-S] ", MENU_SELECTABLE, NULL);
- Menu_AddItem(file_index, " -------------------- ", MENU_DISABLED, NULL);
- Menu_AddItem(file_index, " Quit [CTL-C] ", MENU_SELECTABLE, test_stop);
- } else {
- printf("Could not add menu items to the file (%d) index!\r\n", file_index);
- printf("Program exits.\r\n");
- exit(-1);
- }
-
- if (options_index) {
- Menu_AddItem(options_index, " Display a color dialog ", MENU_SELECTABLE, NULL);
- Menu_AddItem(options_index, " Display a window ", MENU_SELECTABLE, test_window);
- Menu_AddItem(options_index, " Sample options dialog ", MENU_SELECTABLE, test2_win);
- Menu_AddItem(options_index, " ---------------------- ", MENU_DISABLED, NULL);
- Menu_AddItem(options_index, " Save options ", MENU_SELECTABLE, NULL);
- Menu_AddItem(options_index, " ---------------------- ", MENU_DISABLED, NULL);
- Menu_AddItem(options_index, " Get library version ", MENU_SELECTABLE, test_getlib);
- } else {
- printf("Could not add menu items to the options (%d) index!\r\n", options_index);
- printf("Program exits.\r\n");
- exit(-1);
- }
-
- if (settings_index) {
- Menu_AddItem(settings_index, " Dialogs move Opaquely ", MENU_SELECTABLE, c1_opt);
- Menu_AddItem(settings_index, " Color Display ", MENU_SELECTABLE, c2_opt);
- } else {
- printf("Could not add menu items to the settings (%d) index!\r\n", settings_index);
- printf("Program exits.\r\n");
- exit(-1);
- }
-
- Win_Loop();
- Win_Deinitialize();
- }
-
- void demo_keyboard(int c)
- {
- wprintw(_main_win, "Keyboard: %d\n", c);
- }
-
- void main(void)
- {
- if (Win_Initialize()) {
- if (Win_InitializeSound()) {
- Win_SetSound(SOUND_OPEN, "/home/khollis/dev/win/demo/Tenchi-opening.au");
- } else {
- wprintw(_main_win, "Uh oh, the sound server isn't running.\n");
- wprintw(_main_win, "Better type \"sound_server &\" before running this\n");
- wprintw(_main_win, "program again. Sound support will be disabled for\n");
- wprintw(_main_win, "this program session.\n");
- }
- Win_SetCallbackKEYBOARD(demo_keyboard);
- Win_PlaySound(SOUND_START);
- do_demo();
- Win_Deinitialize();
- } else {
- printf("Cannot initialize.\n");
- exit(0);
- }
- }
-